function FLogSaveStarbase () {
    var server = top.FLogGetServer ();
    var facility = server.GetStarbase (window.userloc, "facility");

    facility["sector"] = POgetSector ();
    var coords = POgetCoords ();
    coords[0] = "(";
    coords[coords.length-1] = ")";
    facility["coords"] = coords;
    facility["player_owned"] = "false";
      
    var spans = document.getElementsByTagName ("span");
    for (var i=0; i<spans.length; i++) {
        var style = spans[i].getAttribute ("style");
        if (!style) continue;
        
        if (style == "font-size:24px;font-weight:bold;") {
            facility["name"] = spans[i].textContent;
            
            try {
                var img = spans[i].parentNode.nextSibling.firstChild.getAttribute ("src").split("/");
                facility["rings"] = Number (img[img.length-1].split("_")[2][1]);
            } catch (e) {
                facility["rings"] = "???";
            }
            break;
        }
    }
    
    var tds = document.getElementsByTagName ("td");
    for (var i=0; i<tds.length; i++) {
        var td = tds[i];
        if (td.textContent == "Workers:") {
            td = td.nextSibling;
            facility["population"] = td.textContent.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
        }
    }
    
    var ths = document.getElementsByTagName ("th");
    for (var i=0; i<ths.length; i++) {
        var th = ths[i];
        if (th.textContent != "Commanded by") continue;
        facility["owner"] = th.parentNode.nextSibling.cells[1].firstChild.textContent;
        try {
            facility["owner_alliance"] = th.parentNode.nextSibling.cells[1].getElementsByTagName ("font")[0].textContent;
        } catch (e){
            facility["owner_alliance"] = "";
        }
        try {
            var img = th.parentNode.nextSibling.cells[0].getElementsByTagName ("img")[0];
            var src = img.getAttribute("src").split("/");
            src = src[src.length-1].split("_")[1];
            if (src == 'fed') {
                facility["faction"] = "Federation";
            } else if (src == "uni") {
                facility["faction"] = "Union";
            } else if (src == "emp") {
                facility["faction"] = "Empire";
            }
        } catch (e){
            facility["faction"] = "Neutral";
        }
        facility["player_owned"] = "true";
        break;
    }
    
    server.SaveFacility (window.userloc, facility, "facility");
}

FLogSaveStarbase();